import React, { Component } from 'react'

import { CSSTransition,TransitionGroup } from 'react-transition-group'
// 引入对应的css
import './CssTransition.css'

export default class CssGroup extends Component {
  constructor() {
    super();
    this.state = {
      list: [
        {id: 0, name: 'Html'},
        {id: 1, name: 'Css'},
        {id: 2, name: 'Js'},
      ]
    }
  }
  delItem(index) {
    // splice是会修改原数组的操作，经过splice之后，数组已经是正确的结果了
    this.state.list.splice(index, 1);
    this.setState({
      list: this.state.list
    })
  }
  render() {
    return (
      <div>
        <TransitionGroup>
          {
            this.state.list.map((item,index) => {
              return (
                // key={item.id}循环显示多个节点，所以需要可以
                <CSSTransition timeout={1000} key={item.id} classNames="react">
                  <div onClick={()=>this.delItem(index)}>{item.name}</div>
                </CSSTransition>
              )
            })
          }
        </TransitionGroup>
      </div>
    )
  }
}
